package ocr

import (
	"github.com/gin-gonic/gin"
)

// 路由分组
type IRouteGroup interface {
	IRouteBaseCompose
}

// 分组器
type OcrGroup struct {
	ocrGroup *gin.RouterGroup
}

func (o *OcrGroup) Demo(path string, handler ...gin.HandlerFunc) {
	o.ocrGroup.GET(path, handler...)
}

// 使用中间件
func (o *OcrGroup) Use(handles ...OcrHandler) {
	for _, handle := range handles {
		o.ocrGroup.Use(handle.createOcrHandle(o.ocrGroup.BasePath()))
	}
}

// 创建分组
func (o *OcrGroup) Group(path string) IRouteGroup {
	return &OcrGroup{
		ocrGroup: o.ocrGroup.Group(path),
	}
}

// GET
func (o *OcrGroup) GET(path string, handlers ...OcrMiddle) {
	list := make([]gin.HandlerFunc, 0)
	for _, v := range handlers {
		list = append(list, func(ctx *gin.Context) {
			v(ctx)
		})
	}
	o.ocrGroup.GET(path, list...)
}

// POST
func (o *OcrGroup) POST(path string, handlers ...OcrMiddle) {
	list := make([]gin.HandlerFunc, 0)
	for _, v := range handlers {
		list = append(list, func(ctx *gin.Context) {
			v(ctx)
		})
	}
	o.ocrGroup.POST(path, list...)
}

// PUT
func (o *OcrGroup) PUT(path string, handlers ...OcrMiddle) {
	list := make([]gin.HandlerFunc, 0)
	for _, v := range handlers {
		list = append(list, func(ctx *gin.Context) {
			v(ctx)
		})
	}
	o.ocrGroup.PUT(path, list...)
}

// DELETE
func (o *OcrGroup) DELETE(path string, handlers ...OcrMiddle) {
	list := make([]gin.HandlerFunc, 0)
	for _, v := range handlers {
		list = append(list, func(ctx *gin.Context) {
			v(ctx)
		})
	}
	o.ocrGroup.DELETE(path, list...)
}
